package com.yxy.controller;

import com.yxy.base.BusinessException;
import com.yxy.base.Pagingable;
import com.yxy.base.RestResponse;
import com.yxy.dto.TableRankDto;
import com.yxy.dto.ValidationGroups;
import com.yxy.feign.AuthService;
import com.yxy.model.TableRank;
import com.yxy.utils.TokenCheckUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lixinquan
 * 职级信息
 */
@RestController
@Slf4j
@RequestMapping("/tableRank")
public class TableRankController {

  @Autowired
  private TokenCheckUtil tokenCheckUtil;

  @Autowired
  private AuthService authService;
  @Autowired
  private com.yxy.service.TableRankService TableRankService;

  // 获取列表
  @Pagingable
  @PostMapping("/list")
  public RestResponse<List<TableRank>> getList(@RequestBody TableRankDto input) throws BusinessException {
    RestResponse<List<TableRank>> restResponse = new RestResponse<>(200, "成功");
    restResponse.setContent(TableRankService.getlist(input));
    return restResponse;
  }




  //创建与修改
  @PostMapping("/create")
  public RestResponse<TableRank> create(
          @RequestBody @Validated({ValidationGroups.InsertForm.class}) TableRankDto pojo) throws BusinessException {
    RestResponse<TableRank> restResponse = new RestResponse<>(200, "成功");
    restResponse.setContent(TableRankService.save(pojo));
    return restResponse;
  }

  //更新数据
  @PutMapping("/update")
  public RestResponse<TableRank> update(
          @RequestBody @Validated({ValidationGroups.UpdateForm.class}) TableRankDto pojo) throws BusinessException {
    RestResponse<TableRank> restResponse = new RestResponse<>(200, "成功");
    restResponse.setContent(TableRankService.modify(pojo));
    return restResponse;
  }








}
